package com.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.MultipartConfigElement;

@Configuration
public class ImageMapperConfig implements WebMvcConfigurer {

    @Value("${upload.dir}")
    private  String upload;


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String os = System.getProperty("os.name");
        if(os.toLowerCase().startsWith("win")){
            registry.addResourceHandler("/upload/**").addResourceLocations("file:"+upload);
            registry.addResourceHandler("/screen/**").addResourceLocations("file:"+upload+"screen/");
            registry.addResourceHandler("/video/**").addResourceLocations("file:"+upload+"video/");

        }
        else
        {
            registry.addResourceHandler("/upload/**").addResourceLocations(upload);
            registry.addResourceHandler("/screen/**").addResourceLocations(upload+"screen/");
            registry.addResourceHandler("/video/**").addResourceLocations(upload+"video/");
         }

    }
}
